package org.dromara.quickswing.ui.app;

import cn.hutool.core.lang.Assert;

import javax.swing.*;
import java.util.ResourceBundle;

/**
 * @author Jin
 */
public abstract class QSDialog<T extends QSWidget<? extends QSPrefs>> extends JDialog {

    private final T owner;
    private final ResourceBundle bundle;

    protected QSDialog(T owner, String title) {
        super(owner, title);
        this.owner = owner;
        this.bundle = owner.getResourceBundle();
    }

    protected QSDialog(T owner, boolean modal) {
        super(owner, modal);
        this.owner = owner;
        this.bundle = owner.getResourceBundle();
    }

    protected QSDialog(T owner, String title, boolean modal) {
        super(owner, title, modal);
        this.owner = owner;
        this.bundle = owner.getResourceBundle();
    }

    public String $tr(String key) {
        Assert.notNull(bundle);
        return bundle.getString(key);
    }

    public ResourceBundle getResourceBundle() {
        return bundle;
    }

    @Override
    public T getOwner() {
        return owner;
    }
}